package com.bike.bikeserver.controller.backend;

import com.bike.bikeserver.common.annotation.OperationLog;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.vo.UserDeleteVo;
import com.bike.bikeserver.domain.vo.UserLoginVo;
import com.bike.bikeserver.domain.vo.UserRegisterVo;
import com.bike.bikeserver.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/16 15:25
 */
@RestController
@RequestMapping("back/user")
public class BackUserController
{
    @Autowired
    IUserService userService;

    /**
     * 获取验证码
     *
     * @param userRegisterVo
     * @return
     */
    @PostMapping("getCode")
    public CommonResult getCode(@RequestBody UserRegisterVo userRegisterVo)
    {
        return userService.getCode(userRegisterVo);
    }

    /**
     * 用户注册
     *
     * @param userRegisterVo
     * @return
     */
    @PostMapping("register")
    @OperationLog(value = "后台管理系统用户注册:user")
    public CommonResult userRegister(@RequestBody UserRegisterVo userRegisterVo)
    {
        return userService.userRegister(userRegisterVo);
    }

    /**
     * 用户登录
     *
     * @param userLoginVo
     * @return
     */
    @PostMapping("login")
    @OperationLog(value = "后台管理系统用户登录:user")
    public CommonResult userLogin(@RequestBody UserLoginVo userLoginVo)
    {
        return userService.userLogin(userLoginVo.getAccount(), userLoginVo.getPwd());
    }

    /**
     * 用户退出登录
     *
     * @param userId
     * @return
     */
    @GetMapping("logout")
    @OperationLog(value = "后台管理系统用户注销:user")
    public CommonResult userLogout(@RequestParam("userId") Integer userId)
    {
        return userService.userLogout(userId);
    }

    /**
     * 用户密码找回
     *
     * @param userRegisterVo
     * @return
     */
    @PostMapping("findPwd")
    @OperationLog(value = "后台管理系统用户找回密码:user")
    public CommonResult findPwd(@RequestBody UserRegisterVo userRegisterVo)
    {
        return userService.findPwd(userRegisterVo);
    }

    /**
     * 注销账号
     *
     * @param userDeleteVo
     * @return
     */
    @PostMapping("deleteAccount")
    @OperationLog(value = "后台管理系统删除账号:user")
    public CommonResult deleteAccount(@RequestBody UserDeleteVo userDeleteVo)
    {
        return userService.deleteAccount(userDeleteVo);
    }
}